<template>
    <div class="app-container">
        <el-card class="box-card">            
            <div slot="header" class="clearfix">
                <el-button type="primary" icon="el-icon-search" @click="TableSearch">搜 索</el-button>
                <el-button @click="Reset" icon="el-icon-delete">重 置</el-button>
            </div>
            <div class="tb-body">
                <el-form ref="searchFormRef" :model="searchForm" :inline="true" label-width="120px" :style="`flex:1;`">
                    <el-form-item label="迁出户口">
                        <el-paged-select url="/Household/List" columnName="Name" columnValue="Id"
                            v-model="searchForm.HouseholdId">
                        </el-paged-select>
                    </el-form-item>                
                    <el-form-item label="审核状态">
                        <el-paged-select url="/Select/AuditStatus" columnName="Name" columnValue="Value"
                            v-model="searchForm.AuditStatus">
                        </el-paged-select>
                    </el-form-item>                
                    <el-form-item label="原因" prop="Reason">
                        <el-input v-model.trim="searchForm.Reason" placeholder="请输入原因进行精确搜索" ></el-input>
                    </el-form-item>
                    <el-form-item label="审核人">
                        <el-paged-select url="/User/List" columnName="Name" columnValue="Id"
                            v-model="searchForm.AuditUserId">
                        </el-paged-select>
                    </el-form-item>                
                    <el-form-item label="审核原因" prop="AuditReason">
                        <el-input v-model.trim="searchForm.AuditReason" placeholder="请输入审核原因进行精确搜索" ></el-input>
                    </el-form-item>
                    <el-form-item label="迁出户籍个人信息">
                        <el-paged-select url="/User/List" columnName="Name" columnValue="Id"
                            v-model="searchForm.CensusInfoPersonId">
                        </el-paged-select>
                    </el-form-item>                
                    <el-form-item label="迁出前地址" prop="BeforeAddress">
                        <el-input v-model.trim="searchForm.BeforeAddress" placeholder="请输入迁出前地址进行精确搜索" ></el-input>
                    </el-form-item>
                    <el-form-item label="现在地址" prop="NowAddress">
                        <el-input v-model.trim="searchForm.NowAddress" placeholder="请输入现在地址进行精确搜索" ></el-input>
                    </el-form-item>
                </el-form>
            </div>

        </el-card>


        <el-dialog v-dialogDrag title="户口迁出编辑对话框" :visible.sync="editorShow" width="80%" :lock-scroll="true" height="800px">
            <el-form v-if="editorShow == true" ref="editModalForm" :rules="editModalFormRules" :model="formData"
                label-width="140px" size="mini">
                <el-row :gutter="10">
                    <el-col :span="12">
                        <el-form-item label="迁出户口" prop="HouseholdId">
                          <el-paged-select url="/Household/List" columnName="" columnValue="Id"  v-model="formData.HouseholdId" >
                          </el-paged-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="审核状态" prop="AuditStatus">
                          <el-paged-select url="/Select/AuditStatus" columnName="Name" columnValue="Value"  v-model="formData.AuditStatus" >
                          </el-paged-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="原因" prop="Reason">
                            <el-input v-model.trim="formData.Reason"  ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="审核人" prop="AuditUserId">
                          <el-paged-select url="/User/List" columnName="Name" columnValue="Id"  v-model="formData.AuditUserId" >
                          </el-paged-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="审核原因" prop="AuditReason">
                            <el-input v-model.trim="formData.AuditReason"  ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="迁出户籍个人信息" prop="CensusInfoPersonId">
                          <el-paged-select url="/User/List" columnName="" columnValue="Id"  v-model="formData.CensusInfoPersonId" >
                          </el-paged-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="迁出前地址" prop="BeforeAddress">
                            <el-input v-model.trim="formData.BeforeAddress"  ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="现在地址" prop="NowAddress">
                            <el-input v-model.trim="formData.NowAddress"  ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>


                <el-row type="flex" justify="end" align="bottom">
                    <el-form-item>
                        <el-button type="primary" plain @click="CreateOrEditForm()">确 定</el-button>
                        <el-button @click="editorShow = false">取 消</el-button>
                    </el-form-item>
                </el-row>
            </el-form>

        </el-dialog>


        <data-table ref="tableId" url="/HouseholdOut/List" :column="dataColum">
            <template v-slot:header>
                <el-button type="primary" plain icon="el-icon-edit" @click="ShowEditModal()">新 增</el-button>
                <el-button type="danger" plain icon="el-icon-delete" @click="ShowBatchDeleteModal()">批 量 删 除</el-button>
 				 </template>
            <template v-slot:operate="scope">
                <el-button type="text" @click="ShowEditModal(scope.row.Id)">修 改</el-button>
                <el-button type="text" @click="ShowDeleteModal(scope.row.Id)">删 除</el-button>
            </template>
        </data-table>
    </div>
</template>
    
<script>
import store from '@/store';
import { mapGetters } from 'vuex'
export default {
    name: "HouseholdOutList",
 	 computed: {
        ...mapGetters([
            'name', 'roleTypeFormat', 'avatar', 'userId', 'loginTimePeriod', "user", 'userId', 'roleType'
        ])
    },
    data() {

        return {
            lock: 0,//用来防止重复提交的变量
            searchForm: {},//搜索定义的数据对象
            dataColum: [
                {
                    key: "Id",
                    hidden: true,

                },
               {
                    key: "HouseholdId",
                    hidden: true, 
                },
               {
                    key: "AuditStatus",
                    title: "审核状态",
                    type: store.getters.columnType.SHORTTEXT, 
                },
               {
                    key: "Reason",
                    title: "原因",
                    type: store.getters.columnType.SHORTTEXT, 
                },
               {
                    key: "AuditUserId",
                    hidden: true, 
                },
               {
                    key: "AuditReason",
                    title: "审核原因",
                    type: store.getters.columnType.SHORTTEXT, 
                },
               {
                    key: "CensusInfoPersonId",
                    hidden: true, 
                },
               {
                    key: "BeforeAddress",
                    title: "迁出前地址",
                    type: store.getters.columnType.SHORTTEXT, 
                },
               {
                    key: "NowAddress",
                    title: "现在地址",
                    type: store.getters.columnType.SHORTTEXT, 
                },
                {
                    title: "操作",
                    type: store.getters.columnType.USERDEFINED,
                },
            ],
            editModalFormRules: {
              "HouseholdId":[
              ],
              
              "AuditStatus":[
              ],
              
              "Reason":[
                { required: true, message: '该项为必填项', trigger: 'blur' },
              ],
              
              "AuditUserId":[
              ],
              
              "AuditReason":[
                { required: true, message: '该项为必填项', trigger: 'blur' },
              ],
              
              "CensusInfoPersonId":[
              ],
              
              "BeforeAddress":[
                { required: true, message: '该项为必填项', trigger: 'blur' },
              ],
              
              "NowAddress":[
                { required: true, message: '该项为必填项', trigger: 'blur' },
              ],
              
            },
            formData: {

            },//保存或者修改定义的数据对象
            editorShow: false,//编辑弹窗定义的数据对象

        };
    },
    created() {

    },
    methods: {
        /**
         * 点击新增或者编辑的时候会触发
         */
        async ShowEditModal(Id) {

            let { Data } = await this.$Post(`/HouseholdOut/Get`, { Id: Id });
            this.formData = Data;
            this.formData.Behavior=null;
            this.formData.IsEdit=Id!=undefined;
            
            this.editorShow = true;

        },
        /**
         * 点击保存的时候会触发
         */
        async CreateOrEditForm() {
            if (this.lock == 1) return;
            this.$refs.editModalForm.validate(async valid => {
                if (valid) {
                    this.lock = 1;
                    var { Success } = await this.$PostLoading(`/HouseholdOut/CreateOrEdit`, this.formData);
                    this.lock = 0;
                    if (Success) {
                        this.editorShow = false;
                        this.$refs.tableId.reload();
                    }
                }
            })
        },
        /**
         * 单个删除的时候会触发
         */
        async ShowDeleteModal(Id) {
            await this.$PostDelete(`/HouseholdOut/Delete`, { Id: Id });
            this.$refs.tableId.reload();
        },
        /**
         * 批量删除的时候会触发
         */
        async ShowBatchDeleteModal() {
            var ids = this.$refs.tableId.GetSelectionRow().map(x => x.Id);
            await this.$PostDelete(`/HouseholdOut/BatchDelete`, { Ids: ids });
            this.$refs.tableId.reload();
        },
        /**
         * 点击表格搜索按钮会触发
         */
        async TableSearch() {
            this.$refs.tableId.reload(this.searchForm);
        },
        /**
         * 点击清空表单会触发
         */
        async Reset() {
            this.searchForm = {};
            this.$refs.tableId.reload(this.searchForm);
        },

        /**
         * 导入成功
         */
        async ImportSuccess() {

            this.$refs.tableId.reload();
        },


    },
};
</script>
    